package com.quan.weixin.scheduler;

import javax.annotation.PostConstruct;

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.quan.weixin.api.JsTicket;
import com.quan.weixin.api.JsTicketApi;
import com.quan.weixin.api.JsTicketApi.JsApiType;
import com.quan.weixin.common.WeixinContext;

/**
 * 定时获取AccessToken，每个1小时55分获取一次
 * @author yhaoquan
 *
 */
@Component
public class JsApiTicketRefreshTask {

	@PostConstruct
	public void initMethod() {
		this.accessTokenRefreshJob();
	}
	
	@Scheduled(cron = "0 55 0/1 * * ?")
	public void accessTokenRefreshJob() {
		JsTicket jsTicket = JsTicketApi.getJsTicket(JsApiType.jsapi) ;
		WeixinContext.setJsApiTicket(jsTicket.getTicket());
	}
}
